using System;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace ProjectMyFarmAndShe
{
	public partial class Select : ViewController
	{
		private void Awake()
		{
			Global.Mouse = this;
		}

		void Start()
		{
			// Code Here
			ToolIcon.Hide();

			Global.Brawn.Register(brawn =>
				{
					CheckCurrentBrawnCanUseTool(brawn);

				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.OnToolChange.Register(tool =>
				{
					if (tool != null)
					{
						ToolIcon.Show();
						var sprite = ResController.Default.GetToolIconGetKey(tool.Key);
						ToolIcon.sprite = sprite;

						CheckCurrentBrawnCanUseTool(Global.Brawn.Value);
					}
					else
					{
						ToolIcon.Hide();
					}
				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		void CheckCurrentBrawnCanUseTool(float brawn)
		{
			if (brawn < Global.Tool.UseBrawn)
			{
				ToolIcon.Alpha(0.3f);
			}
			else
			{
				ToolIcon.Alpha(1);
			}
		}
	}
}
